package com.one.efaimaly.user;

import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.one.common.config.RouterPath;
import com.one.common.utils.DataCleanManager;
import com.one.common.view.base.BaseActivity;
import com.one.common.view.widget.MyTitleBar;
import com.one.efaimaly.R;
import com.one.common.common.user.preserter.SettingPresenter;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * creator: zhulunjun
 * time:    2018/8/14
 * describe: 设置页面
 */
@Route(path = RouterPath.SETTING)
public class SettingActivity extends BaseActivity<SettingPresenter> {
    @BindView(R.id.tv_cache)
    TextView tvCache;

    @Override
    protected void initPresenter() {
        mPresenter = new SettingPresenter(this,this);
    }

    @Override
    public int getLayoutResId() {
        return R.layout.activity_setting;
    }

    @Override
    protected void initTitle() {
        super.initTitle();
        getMyTitleBar().setMode(MyTitleBar.Mode.BACK_TITLE)
                .setTitleText("设置");
    }

    @Override
    public void initData() {
        super.initData();
        getCache();
    }

    @OnClick({R.id.tv_btn_logout})
    public void logout() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("确定要退出登录？")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        mPresenter.logout();
                        dialog.dismiss();
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                            dialog.dismiss();
                    }
                }).show();
    }

    @OnClick({R.id.ll_cache})
    public void clearCache() {
        DataCleanManager.clearAllCache(this);
        getCache();
    }


    private void getCache(){
        // 获取缓存
        try {
            tvCache.setText(DataCleanManager.getTotalCacheSize(this));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
